//
//  SCRefundDetailController.m
//  shangcheng
//
//  Created by 张艳江 on 2019/6/11.
//  Copyright © 2019 张艳江. All rights reserved.
//

#import "SCRefundDetailController.h"
#import "SCFillinLogisticsController.h"
#import "SCRefundController.h"
#import "SCLogisticsInfoController.h"

@interface SCRefundDetailController ()

@property (weak, nonatomic) IBOutlet UILabel *refundStateLab;
@property (weak, nonatomic) IBOutlet UILabel *refundPriceLab;
@property (weak, nonatomic) IBOutlet UILabel *refundReasonLab;
@property (weak, nonatomic) IBOutlet UILabel *refundTimeLab;
@property (weak, nonatomic) IBOutlet UILabel *handlingTimeLab;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
@property (weak, nonatomic) IBOutlet UIButton *leftBtn;

@property (weak, nonatomic) IBOutlet UILabel *refundTitleLab;
@property (weak, nonatomic) IBOutlet UIView *refundInfoBgView;


@property (strong, nonatomic) SCModel *detailModel;

@end

@implementation SCRefundDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"退款详情";
    self.rightBtn.hidden = YES;
    self.leftBtn.hidden = YES;
    //请求数据
    [self requestDetailData];
}
- (void)requestDetailData{
    
    NSDictionary *dict = @{@"type":self.type,
                           @"token":Token,
                           @"order_id":self.model.order_id};
    NSString *url = [MyTool splicingWithUrl:@"admin.php?g=System&c=GiftAppOrder&a=Service_content"];
    [SVProgressHUD showWithStatus:@"加载中..."];
    [[NetworkRequestTool sharedNetworkTool] POST:url parameters:dict finished:^(id result, NSString *error) {
        NSLog(@"---%@",result);
        [SVProgressHUD dismiss];
        self.detailModel = [SCModel mj_objectWithKeyValues:result[@"data"]];
        
        //设置状态
        if ([self.detailModel.status intValue] == 11 || [self.detailModel.status intValue] == 12) {
            self.refundStateLab.text = @"等待商家处理";
            self.leftBtn.hidden = NO;
            [self.leftBtn setTitle:@"撤销申请" forState:0];
            self.rightBtn.hidden = NO;
            [self.rightBtn setTitle:@"修改申请" forState:0];
        }else if ([self.detailModel.status intValue] == 7){
            self.refundStateLab.text = @"退款失败";
        }else if ([self.detailModel.status intValue] == 7){
            self.refundStateLab.text = @"商家已同意";
            self.leftBtn.hidden = NO;
            [self.leftBtn setTitle:@"撤销申请" forState:0];
            self.rightBtn.hidden = NO;
            [self.rightBtn setTitle:@"填写物流" forState:0];
        }else if ([self.detailModel.status intValue] == 8){
            self.refundStateLab.text = @"退款中";
        }else if ([self.detailModel.status intValue] == 9){
            self.refundStateLab.text = @"退款成功";
        }else if ([self.detailModel.status intValue] == 10){
            self.refundStateLab.text = @"交易关闭";
        }else if ([self.detailModel.status intValue] == 13){
            self.refundStateLab.text = @"您已撤销";
            self.refundTitleLab.hidden = YES;
            self.refundInfoBgView.hidden = YES;
        }else if ([self.detailModel.status intValue] == 14){
            self.refundStateLab.text = @"商家等待收货";
            self.rightBtn.hidden = NO;
            [self.rightBtn setTitle:@"查看物流" forState:0];
        }
        //退款信息
        if ([self.type intValue] == 1) {//积分商城
            self.refundPriceLab.text = [NSString stringWithFormat:@"%@福豆",self.detailModel.sum_integral];
        }else{
            
        }
        self.refundReasonLab.text = self.detailModel.content;
        self.refundTimeLab.text = [MyTool getTimeFromTimesTamp:self.detailModel.create_time];
        
    }];
}
//点击按钮事件
- (IBAction)clickBtns:(UIButton *)sender {
    
    if ([sender.titleLabel.text isEqualToString:@"撤销申请"]) {
        [MyTool alertTitle:@"您确定要撤销退款/退货申请吗?" mesasge:nil preferredStyle:UIAlertControllerStyleAlert confirmHandler:^(UIAlertAction * _Nonnull action) {
            
            NSDictionary *dict = @{@"type":self.type,
                                   @"token":Token,
                                   @"id":self.detailModel.id};
            NSString *url = [MyTool splicingWithUrl:@"admin.php?g=System&c=GiftAppOrder&a=Service_cancel"];
            [SVProgressHUD showWithStatus:@"撤销中..."];
            [[NetworkRequestTool sharedNetworkTool] POST:url parameters:dict finished:^(id result, NSString *error) {
                [SVProgressHUD showSuccessWithStatus:@"撤销成功"];
                [self.navigationController popViewControllerAnimated:YES];
            }];
            
        } cancleHandler:nil viewController:self];
    }else if ([sender.titleLabel.text isEqualToString:@"修改申请"]){
        
        SCRefundController *vc = [[SCRefundController alloc]init];
        vc.goodsModel = self.model;
        vc.goodsModel.type = self.detailModel.type;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if ([sender.titleLabel.text isEqualToString:@"填写物流"]){
        SCFillinLogisticsController *vc = [[SCFillinLogisticsController alloc]init];
        vc.type = self.type;
        vc.i_d = self.detailModel.id;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if ([sender.titleLabel.text isEqualToString:@"查看物流"]){
        
        SCLogisticsInfoController *vc = [[SCLogisticsInfoController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}


@end
